<template>
<div>
  <el-breadcrumb separator="/">
    <el-breadcrumb-item :to="{ path: '/Home' }">首页</el-breadcrumb-item>
    <el-breadcrumb-item>日志管理</el-breadcrumb-item>
  </el-breadcrumb>

  <el-card>
    <el-row :gutter="20">
      <el-col :span="8">
        <el-input placeholder="请输入管理员姓名" clearable v-model="name" @clear="searchLog">
          <el-button slot="append" icon="el-icon-search" @click.prevent="searchLog"></el-button>
        </el-input>
      </el-col>
      <el-col :span="4">
        <el-button type="primary" @click.prevent="delBatch()" :disabled="this.sels.length===0">批量删除</el-button>
      </el-col>
    </el-row>


    <el-table
        ref="multipleTable"
        :data="logList"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange">
      <el-table-column
          type="selection"
          width="55">
      </el-table-column>
      <el-table-column
          prop="name"
          label="日志编号"
          width="300">
        <template slot-scope="scope">{{ scope.row.id }}</template>
      </el-table-column>
      <el-table-column
          label="日期"
          width="300">
        <template slot-scope="scope">{{ scope.row.insertTime }}</template>
      </el-table-column>
      <el-table-column
          prop="name"
          label="管理员"
          width="300">
        <template slot-scope="scope">{{ scope.row.managerName }}</template>
      </el-table-column>
      <el-table-column
          prop="name"
          label="日志内容"
          width="300">
        <template slot-scope="scope">{{ scope.row.content }}</template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="danger" size="mini" @click.prevent="removeLogById(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

<!--    <el-table :data="logList" border stripe>-->
<!--      <el-table-column label="#" type="index"></el-table-column>-->
<!--      <el-table-column label="日志编号" prop="id"></el-table-column>-->
<!--      <el-table-column label="管理员" prop="managerName"></el-table-column>-->
<!--      <el-table-column label="内容" prop="content"></el-table-column>-->
<!--      <el-table-column label="创建时间" prop="insertTime"></el-table-column>-->
<!--      <el-table-column label="操作">-->
<!--        <template slot-scope="scope">-->
<!--          <el-button type="danger" size="mini" @click.prevent="removeLogById(scope.row.id)">删除</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--    </el-table>-->
    <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNum"
        :page-sizes="[10, 15 , 20, 30]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
    ></el-pagination>
  </el-card>
</div>
</template>

<script>
export default {
  name: "Log",
  data(){
    return{
      pageNum:1,
      pageSize:10,
      total:0,
      name:'',
      logList:[],
      managerName:'',
      multipleSelection:[],
      sels:[]
    }
  },
  methods:{
    handleSizeChange(size){
      this.pageSize = size ;
      this.pageNum = 1;
      this.initLog();
    },
    handleCurrentChange(now){
      this.pageNum = now ;
      this.initLog();
    },

    handleSelectionChange(sels) {
      this.sels = sels;
      console.log(sels);
      // this.multipleSelection = val;
      // console.log("++++++++++++++++++++++++++++++")
      // console.log(this.multipleSelection)
      // console.log("++++++++++++++++++++++++++++++")
      // let multipleSelection=[];
      // for (multipleSelection of val){
      //   console.log("-----------------------------")
      //   console.log(multipleSelection.id);
      //   console.log("-----------------------------")
      //   this.push(multipleSelection.id);
      // }


    },
    searchLog(){
      this.initLog();
    },



    //---------------------------------------------获取日志------------------------------------------------
    initLog(){
      let url = "/log/list";
      this.$axios.get(url,{
        params:{
          now:this.pageNum,
          size:this.pageSize,
          name:this.name
        }
      }).then(res=>{
        if(res.data.code == 200){
          this.logList = res.data.data.list ;
          this.pageSize = res.data.data.pageSize;
          this.pageNum = res.data.data.pageNum ;
          this.total = res.data.data.total ;
          console.log(this.logList)
        }else {
          this.$message({
            type:'error',
            message:res.data.msg,
            duration:1000
          })
        }
      })
    },





    //---------------------------------------------单个删除------------------------------------------------
    removeLogById(id){
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let url = "/log/del/"+id ;
        this.$axios.delete(url)
            .then(res=>{
              if (res.data.code == 200){
                this.$message({
                  type:"success",
                  message:res.data.msg,
                  duration:1000
                })
                this.initLog();
              }else {
                this.$message({
                  type:"error",
                  message:res.data.msg,
                  duration:1000
                })
              }
            })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },



    //---------------------------------------------批量删除------------------------------------------------
    delBatch(){
     // const ids = this.sels.map(item => item.id).join(",")
 //     console.log("++++++++++++++++++++++++++++++")
   //   console.log(ids)
   //   console.log("++++++++++++++++++++++++++++++")
      const ids = []
      for (const  v of this.sels){
        ids.push(v.id)
      }
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let url = "/log/delBatch/" ;
        this.$axios.post(url,ids)
            .then(res=>{
              if (res.data.code == 200){
                this.$message({
                  type:"success",
                  message:res.data.msg,
                  duration:1000
                })
                this.initLog();
              }else {
                this.$message({
                  type:"error",
                  message:res.data.msg,
                  duration:1000
                })
              }
            })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    }
  },
  created() {
    this.initLog();
  }
}
</script>

<style scoped>

</style>